package com.jmyd.coupon.server.enums;

import com.jmyd.commons.base.vo.LabelStringKeyVo;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 优惠券使用状态
 *
 * @author samphin
 * @since 2021-7-14 13:40:20
 */
public enum SceneCouponUsePlatformEnum {
    /**
     * 使用状态(0:未使用 1:已使用 2:已过期)
     */
    PC("PC", "PC端"),
    APP("APP", "APP端"),
    H5("H5", "H5端"),
    APPLET("APPLET", "小程序"),

    ;

    @Getter
    private String code;
    @Getter
    private String desc;

    SceneCouponUsePlatformEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String getByCode(String code) {
        Optional<SceneCouponUsePlatformEnum> optional = Arrays.stream(SceneCouponUsePlatformEnum.values()).filter(en -> en.getCode().equals(code)).findFirst();
        return optional.map(SceneCouponUsePlatformEnum::getDesc).orElse(null);
    }

    public static List<LabelStringKeyVo> queryList() {
        return Arrays.stream(SceneCouponUsePlatformEnum.values()).map(en->{
            LabelStringKeyVo vo = new LabelStringKeyVo();
            vo.setKey(en.code);
            vo.setValue(en.desc);
            return vo;
        }).collect(Collectors.toList());
    }
}
